home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
graphic
/
dbwrendr.zip
/
SOURCE
/
FIL.C
< prev
next >
Wrap
Text File
|
1989-10-31
|
19KB
|
549 lines
/************************************************************************
* *
* Copyright (c) 1987, David B. Wecker *
* All Rights Reserved *
* *
* This file is part of DBW_Render *
* *
* DBW_Render is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY. No author or distributor accepts *
* responsibility to anyone for the consequences of using it or for *
* whether it serves any particular purpose or works at all, unless *
* he says so in writing. Refer to the DBW_Render General Public *
* License for full details. *
* *
* Everyone is granted permission to copy, modify and redistribute *
* DBW_Render, but only under the conditions described in the *
* DBW_Render General Public License. A copy of this license is *
* supposed to have been given to you along with DBW_Render so you *
* can know your rights and responsibilities. It should be in a file *
* named COPYING. Among other things, the copyright notice and this *
* notice must be preserved on all copies. *
************************************************************************
* *
* Authors: *
* DBW - David B. Wecker *
* jhl - John H. Lowery *
* *
* Versions: *
* V1.0 870125 DBW - First released version *
* V1.01 880916 jhl - IBM PC (VGA/MCGA) conversion *
* 890121 jhl - MAXROW & MAXCOL become variables, add *
* 'D' command for Display max <hor> <vert> *
* V1.02 891031 jhl - add MAXCOL and MAXROW as first two integers *
* in output file, so multiple formats can be *
* supported. *
* *
************************************************************************/
#define MODULE_FILEIO
#include "ray.h"
static long *fracopp;
static triangle *scr_t;
static extent *scr_e;
static sphere *scr_s;
static quad *scr_q;
static ring *scr_r;
static cylinder *scr_c;
static int whichf;
void dumpnode(n)
node *n;
{
while (n)
{
switch (n->kind)
{
case EXTENT :
printf("extent\n");
vecdump(eptr(n)->center,"center");
printf("radius = %f\n",eptr(n)->radius);
dumpnode(((extent *) n)->sub);
break;
case SPHERE :
printf("sphere\n");
break;
case TRIANGLE :
printf("triangle\n");
break;
case QUAD :
printf("quad\n");
break;
case RING :
printf("ring\n");
break;
default :
printf("UNKNOWN KIND %d\n",n->kind);
break;
}
n = n->next;
}
printf("end\n");
}
void copyattr( oa, na )
attributes *oa, *na;
{
na->ref = oa->ref;
na->idx = oa->idx;
na->fuz = oa->fuz;
na->tex = oa->tex;
veccopy( oa->tra, na->tra );
veccopy( oa->amb, na->amb );
veccopy( oa->dif, na->dif );
}
void read_vec(v)
vector v;
{
fscanf(df,"%f %f %f",&v[0],&v[1],&v[2]);
}
void read_attr(attr)
attributes *attr;
{
fscanf(df,"%d %f %f %f",&attr->tex,&attr->fuz,&attr->ref,&attr->idx);
read_vec(attr->tra);
read_vec(attr->amb);
read_vec(attr->dif);
if (attr->tra[0] > 0.0 || attr->tra[1] > 0.0 || attr->tra[2] > 0.0)
allopaque = 0;
attr->fuz /= 10.0; /* Assume more reasonable scale */
}
void dofractal(level,a,b,c,attr)
int level;
vector a,b,c;
attributes *attr;
{
float aclen,bclen,ablen;
vector ab,ac,bc,abbump,acbump,bcbump,v1;
long *savedopp;
if (level == 1)
{
CHECK_ALLOC(scr_t,triangle);
*fracopp = (long)scr_t;
tptr(*fracopp)->next = NULL;
tptr(*fracopp)->kind = TRIANGLE;
copyattr(attr,&tptr(*fracopp)->attr);
veccopy(a,tptr(*fracopp)->position);
vecsub(c,a,ac);
veccopy(ac,tptr(*fracopp)->ve);
vecsub(b,a,ab);
veccopy(ab,tptr(*fracopp)->vp);
fracopp = (long *) &tptr(*fracopp)->next;
}
else
{
level--;
/* compute four subfaces */
/* length of edges */
vecsub(a,c,v1);
aclen = norm(v1);
vecsub(a,b,v1);
ablen = norm(v1);
vecsub(b,c,v1);
bclen = norm(v1);
/* edge midpoints */
vecsum(a,c,ac);
vecscale(0.5,ac,ac);
vecsum(a,b,ab);
vecscale(0.5,ab,ab);
vecsum(b,c,bc);
vecscale(0.5,bc,bc);
/* midpoint perturbations */
noise3(ac,acbump);
if (ac[1] == 0.0)
acbump[1] = 0.0;
noise3(ab,abbump);
if (ab[1] == 0.0)
abbump[1] = 0.0;
noise3(bc,bcbump);
if (bc[1] == 0.0)
bcbump[1] = 0.0;
acbump[0] *= fractal[whichf].xscale;
acbump[1] *= fractal[whichf].yscale;
acbump[2] *= fractal[whichf].zscale;
bcbump[0] *= fractal[whichf].xscale;
bcbump[1] *= fractal[whichf].yscale;
bcbump[2] *= fractal[whichf].zscale;
abbump[0] *= fractal[whichf].xscale;
abbump[1] *= fractal[whichf].yscale;
abbump[2] *= fractal[whichf].zscale;
/* scale the perturbations proportional to side length */
vecscale(aclen,acbump,acbump);
vecscale(ablen,abbump,abbump);
vecscale(bclen,bcbump,bcbump);
/* new perturbed midpoints */
vecsum(abbump,ab,ab);
vecsum(acbump,ac,ac);
vecsum(bcbump,bc,bc);
CHECK_ALLOC(scr_e,extent);
*fracopp = (long)scr_e;
eptr(*fracopp)->next = NULL;
eptr(*fracopp)->kind = EXTENT;
eptr(*fracopp)->sub = NULL;
savedopp = &*fracopp;
fracopp = (long *) &eptr(*fracopp)->sub;
dofractal(level,a, ab,ac,attr);
dofractal(level,ac,bc,c, attr);
dofractal(level,ab,b, bc,attr);
dofractal(level,ac,ab,bc,attr);
fracopp = (long *) &eptr(*savedopp)->next;
}
}
void readimagefile(opp)
long *opp;
{
triangle temp;
vector a,b,c;
while (EOF != fscanf(df,"%1s",str))
switch(str[0])
{
case 'D' :
fscanf(df,"%d %d",&MAXCOL,&MAXROW);
if (MAXCOL > MAXX)
MAXCOL = MAXX;
if (MAXROW > MAXY)
MAXROW = MAXY;
break;
case 'R' :
fscanf(df,"%f",&maxhours);
break;
case 'N' :
fscanf(df,"%f",&idxref);
break;
case 'Z' :
fscanf(df,"%d",&histogram);
break;
case 'a' :
fscanf(df,"%f",&ambscale);